<?php


namespace Drupal\shushengyuan;


use Drupal\shusy_store_order\Entity\ShusyStoreOrder;

class ShushengyuanCronController {

  function cron() {
    //订单过期操作
    $query = db_select('shusy_store_order', 'o');
    $query->leftJoin('shusy_store_order_validity', 'v', 'o.id=v.store_order_id');
    $query->fields('o', ['id']);
    $query->condition('v.validity', REQUEST_TIME, '<');
    $query->condition('o.status', 2);
    $query->range(0, 50);
    $query->orderBy('o.id');
    $result = $query->execute();
    while ($row = $result->fetchAssoc()) {
      //状态 0 取消 1 购物车 2 待支付 3 待发货 4 待收货 5 待评价 6 已完成 7 未提交
      $order = shusy_store_order_load($row['id']);
      if ($order instanceof ShusyStoreOrder) {
        $order->status = 0;
        $order->save();
      }
    }



  }
}
